﻿@{
    ViewBag.Title = "Index";
}
<div class="layui-form-item">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" id="Code" placeholder="库位编号" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="所属仓库" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="所属园区" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="所属公司" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="省份" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="城市" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="区县" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <a class="layui-btn" id="btnSearch">搜索</a>
    </div>
</div>
<table id="table" class="layui-table" lay-filter="table"></table>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        @Html.LayuiButton("position", "三维定位", "layui-btn layui-btn-sm", "/Resource/Location/Index")
        @Html.LayuiButton("add", "添加库位", "layui-btn layui-btn-sm", "/Resource/Location/Add")
        @Html.LayuiButton("edit", "编辑库位", "layui-btn layui-btn-sm", "/Resource/Location/Edit")
        @Html.LayuiButton("imageShow", "图片查看", "layui-btn layui-btn-sm", "/Resource/Location/ImageShow")
        @Html.LayuiButton("imageUpload", "图片上传", "layui-btn layui-btn-sm", "/Resource/Location/ImageUpload")
        @*@Html.LayuiButton("imageIndex", "图片管理", "layui-btn layui-btn-sm", "/Resource/Location/ImageIndex")*@
        @*@Html.LayuiButton("delete", "删除", "layui-btn layui-btn-sm", "/Resource/Location/Index")*@
    </div>
</script>
@*<script type="text/html" id="rowbar">
    @Html.LayuiButton("edit", "修改", "layui-btn layui-btn-primary layui-btn-xs", "/Resource/Location/Index")
    @Html.LayuiButton("del", "删除", "layui-btn layui-btn-danger layui-btn-xs", "/Resource/Location/Index")
</script>*@
<script>
    layui.use(['table', 'layer'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        //查询
        function getWhere() {
            var where = { Code: $("#Code").val() };
            return where;
        }
        layui.tableReload = function () {
            table.reload("table", {
                where: getWhere(),
                page: { curr: 1 }
            });
        }
        $("#btnSearch").click(function () {
            layui.tableReload();
        })
        // 渲染表格
        table.render({
            id: "table",
            elem: '#table',
            method: "post",
            url: 'List',
            cellMinWidth: 80,
            toolbar: "#toolbar",
            cols: [
                [
                    { type: 'checkbox' },
                    { field: 'Code', title: '库位编号' },
                    { field: 'Area', title: '库位面积' },
                    { field: 'StorehouseCode', title: '所属仓库' },
                    { field: 'TypeName', title: '仓库类型' },
                    { field: 'ParkCode', title: '所属园区' },
                    { field: 'ProvinceName', title: '省份' },
                    { field: 'CityName', title: '城市' },
                    { field: 'CountyName', title: '区县' },
                    { field: 'Length', title: '长度' },
                    { field: 'Width', title: '宽度' },
                    { field: 'Height', title: '高度' },
                    { field: 'Description', title: '库位描述' },
                    {
                        field: 'IsRented', title: '是否租赁', templet: function (d) {
                            return d.IsRented ? "是" : "否";
                        }
                    },
                    { field: 'RentDeptName', title: '租赁单位' },
                    { field: 'CreateDate', title: '创建日期' },
                    //{ fixed: 'right', title: '操作', align: 'center', toolbar: '#rowbar' }
                ]
            ],
            done: function (res, curr, count) { //res 即为原始返回的数据
                //console.log(res);
            },
            loading: false,
            event: true,
            page: { limit: 20 }
        });
        //监听头部事件
        table.on('toolbar(table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            if (obj.event != 'add') {
                if (data.length === 0) {
                    layer.msg('请选择一行');
                    return;
                } else if (data.length > 1) {
                    layer.msg('只能同时操作一个');
                    return;
                }
            }
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: '新增库位',
                        maxmin: false,
                        area: ['400px', '440px'],
                        content: 'Add',
                        end: function () {
                            layui.tableReload();
                        },
                        success: function (layero, index) {
                            layer.iframeAuto(index);
                        }
                    });
                    break;
                case 'edit':
                    layer.open({
                        type: 2,
                        title: '编辑库位',
                        maxmin: false,
                        area: ['400px', '440px'],
                        content: 'Edit?id=' + data[0].ID,
                        end: function () {
                            layui.tableReload();
                        },
                        success: function (layero, index) {
                            layer.iframeAuto(index);
                        }
                    });
                    break;
                case 'position':
                    layer.open({
                        type: 2,
                        title: '定位库位',
                        maxmin: false,
                        area: ['100%', '100%'],
                        content: '/Resource/Show3D/ShowPosition?ParkID=' + data[0].ParkID + "&Code=" + data[0].Code
                    });
                    break;
                case 'imageShow':
                    $.ajax({
                        url: 'ImageShow',
                        data: { id: data[0].ID},
                        success: function (res) {
                            if (res.count > 0) {
                                layer.photos({
                                    photos: res.data
                                    , anim: 5
                                });
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                    break;
                case 'imageUpload':
                    layer.open({
                        type: 2,
                        title: '图片上传',
                        maxmin: false,
                        area: ['600px', '400px'],
                        content: 'ImageAdd?id=' + data[0].ID,
                        end: function () {
                            //layui.tableReload();
                        }
                    });
                    break;
                case 'imageIndex':
                    layer.open({
                        type: 2,
                        title: '图片管理',
                        maxmin: false,
                        area: ['600px', '400px'],
                        content: 'ImageIndex?id=' + data[0].ID,
                        end: function () {
                            //layui.tableReload();
                        }
                    });
                    break;
            };
        });
    });
</script>
